package com.heima.jopo.servlet;

import com.heima.jopo.obj.UserInfo;
import com.heima.jopo.web.DelectUser;
import com.heima.jopo.web.SeleList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "dlet", urlPatterns = "/dlet")
public class DeleServlet extends HttpServlet {


    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String id = request.getParameter("id");


        DelectUser dele = new DelectUser();

        try {
            boolean  b = dele.delectUser(id);

            if (b == true) {
                //删除完 重新加载集合的数据 插入到前段主页
                SeleList seleList=new SeleList();
                List<UserInfo> listuser = seleList.listuser();

                HttpSession session = request.getSession();
                session.setAttribute("seleUser",listuser);

//                request.setAttribute("seleUser",listuser);
//                //然后进行到主页跳转
//                request.getRequestDispatcher("main.jsp").forward(request,response);

                response.sendRedirect("main.jsp");
            } else {

                request.getRequestDispatcher("errer.jsp").forward(request,response);
            }

        } catch (Exception e) {
            e.printStackTrace();
            request.getRequestDispatcher("errer.jsp");
        }


    }
}
